
procedure bbbsort(var x : array of integer);
var
   i, j, n : integer;
   for i   : = 1 to n-1 do
   begin
      sorted = true;
      for index := n downto i+1 do
	 if x[index-1] > x[index] then
	 begin
	    exchange(index-1, index);
	    sorted = false
	 end;
      if sorted then exit;
   end;
end.

